package io.renren.wechat.authen.common;

import io.renren.wechat.authen.entity.JsapiTicket;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by 薛冰 on 2016-06-30.
 */
public class Constant {

    //获取token及openid的地址
    public final static String OPENID_PATH = "http://xuebing.natapp1.cc/iyx/wechat/userInfo";
    //获取token及openid的地址
    public final static String APPID = "wx3b12c15fe6135031";

    //微信认证通过后，本系统用户转发的地址
    public final static String INDEX_PATH = "http://xuebing.natapp1.cc/#/wechatlogin";

    //微信认证通过后，需注册的用户
    public final static String EEGISTER_PATH = "http://xuebing.natapp1.cc/wechatlogin.html?t=2/#/wechatregister";

    //注册通过后，重定向的地址
    public final static String RELAOD_PATH = "http://xuebing.natapp1.cc/iyx/wechat/authorize?returnUrl=123";
    //获取jsapi
    public final static String js_api_ticket_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";

    public static String SHA1(String decript) {
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1");
            digest.update(decript.getBytes());
            byte messageDigest[] = digest.digest();
            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            // 字节数组转换为 十六进制 数
            for (int i = 0; i < messageDigest.length; i++) {
                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
                if (shaHex.length() < 2) {
                    hexString.append(0);
                }
                hexString.append(shaHex);
            }
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

}
